<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    {{--<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />--}}
    <meta http-equiv="Cache-Control" content="no-siteapp" />

    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="{{asset('xAdmin/css/font.css')}}">
    <link rel="stylesheet" href="{{asset('xAdmin/css/xadmin.css')}}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="{{asset('xAdmin/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{asset('xAdmin/js/xadmin.js')}}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        .font-24 {
            font-size: 24px;
        }
    </style>

</head>
<body>
<div class="x-body">
    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>英文角色名</th>
            <th>中文角色名</th>
            <th>创建时间</th>
            <th>状态</th>
            <th>操作</th></tr>
        </thead>
        <tbody>
        @foreach($roles as $role)
            <tr>
                <td>{{$role['id']}}</td>
                <td>{{$role['name']}}</td>
                <td>{{$role['name_cn']}}</td>
                <td>{{$role['create_time']}}</td>
                <td>{{$role['auth_text']}}</td>
                <td class="td-manage">
                    @if($role['authStatus'] == 1)
                        <a title="禁用" onclick="disable(this, '{{$role["id"]}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#x1007;</i>
                        </a>
                    @endif
                    @if($role['authStatus'] == 0)
                        <a title="启用" onclick="enable(this, '{{$role["id"]}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#x1005;</i>
                        </a>
                    @endif
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>
</div>
<script>
    /*角色-移除*/
    function disable(obj, id){
        layer.confirm('确认要禁用吗？',function(){
            //发异步删除数据
            $.ajax({
                url: '{{url("backstage/user/auth/remove/role")}}',
                type: 'post',
                dataType: 'json',
                data: {"auth_id": "{{$id}}", "role_id": id, "_token": "{{csrf_token()}}"},
                success: function (result) {
                    if (result.status === 0) {
                        $(obj).parents("tr").remove();
                        layer.msg('已禁用!', {icon: 1, time: 1000});
                        location.href = '{{url("backstage/user/auth/$id/give")}}';
                        return false;
                    }
                    layer.msg(result.msg);
                    return false;
                },
                error: function () {
                    layer.msg('禁用失败，请重试！');
                    return false;
                }
            });
            return false;
        });
    }

    /*角色-赋予*/
    function enable(obj, id){
        layer.confirm('确认要启用吗？',function(){
            //发异步删除数据
            $.ajax({
                url: '{{url("backstage/user/auth/give/role")}}',
                type: 'post',
                dataType: 'json',
                data: {"auth_id": "{{$id}}", "role_id": id, "_token": "{{csrf_token()}}"},
                success: function (result) {
                    if (result.status === 0) {
                        $(obj).parents("tr").remove();
                        layer.msg('已启用!', {icon: 1, time: 1000});
                        location.href = '{{url("backstage/user/auth/$id/give")}}';
                        return false;
                    }
                    layer.msg(result.msg);
                    return false;
                },
                error: function () {
                    layer.msg('启用失败，请重试！');
                    return false;
                }
            });
            return false;
        });
    }
</script>
</body>
</html>
